package com.htjc.uep.center.basic.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.htjc.uep.center.basic.mapper.ConsumePoolMapper;
import com.htjc.uep.center.basic.service.IConsumeService;
import com.htjc.uep.center.commons.utils.JsonUtil;
import com.htjc.uep.center.model.basic.request.ConsumePoolRequest;
import com.htjc.uep.center.model.entity.UpPool;
import com.htjc.uep.center.model.enums.ErrorStatus;
import com.htjc.uep.center.model.enums.PoolStatus;

@Service
public class ConsumeServiceImpl implements IConsumeService{

	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private ConsumePoolMapper poolMapper;
	
	@Override
	public String consumePool(ConsumePoolRequest poolRequest) {
		log.info("====>>>>积分池扣减业务开始<<<<====");
		//查询积分池状态
		UpPool upPool = poolMapper.queryUpPool(poolRequest.getMechanismCode(), poolRequest.getAccountCode(), PoolStatus.POOL_STATUS_01.getCode());

		if (upPool == null) {
			log.info("====>>>>积分池扣减业务<<<<====积分池异常,合作平台编码={},结算单位编码={}", poolRequest.getMechanismCode(), poolRequest.getAccountCode());
			return JsonUtil.getError(ErrorStatus.ERROR_POOL_NULL);
		}
		//积分池扣减
		//暂不锁定积分池
		poolMapper.consumePool(upPool.getPOOL_ID(), poolRequest.getScore());
		return JsonUtil.getSuccess("");
	}
}



















